# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

from jms.dm import jms_dm__dm_cn_departure_transfer_timely_route_dt

jms_dm__dm_cn_departure_transfer_timely_store_agg_dt = SparkSqlOperator(
    task_id='jms_dm__dm_cn_departure_transfer_timely_store_agg_dt',
    email=['zhangqinglin@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_cn_departure_transfer_timely_store_agg_dt_{{ execution_date | date_add(1) | cst_ds }}',
    email_on_retry=True,
    retries=0,
    sql='jms/dm/dm_cn_departure_transfer_timely_store_agg_dt/execute.sql',
    yarn_queue='pro',
    driver_memory='4G',
    driver_cores=4,
    executor_memory='5G',
    executor_cores=8,
    pool_slots=5,
    pool='unlimited_pool',
    num_executors=10,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.executor.memoryOverhead': '5G',
          'spark.dynamicAllocation.enabled': 'true',
          'spark.shuffle.service.enabled': 'true',
          'spark.dynamicAllocation.maxExecutors': 150,
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',
          'spark.dynamicallocation.enabled': 'true',
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,
          'spark.sql.shuffle.partitions': 6000
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 5000,
              'hive.exec.max.dynamic.partitions': 30000
              },
    execution_timeout=timedelta(minutes=30),
    priority_weight=1,
)

jms_dm__dm_cn_departure_transfer_timely_store_agg_dt << [
    jms_dm__dm_cn_departure_transfer_timely_route_dt
]
